package com.pro.addresslist.tools;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class runNumber {

	public static void main(String[] args) {	
	}

	// 后四位格式长度
	private static final String SERIAL_NUMBER = "XXXX";

	/**
	 * 获取数据下一条数据
	 * @param sno 最后四位数字
	 * @return  不带前缀的流水号
	 */
	public String generaterNextNumber(String sno){
		String id = null;
		Date date = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmssms");
		if (sno == null) {
			id = formatter.format(date) + "0001";//201610180001
		} else {
			int count = SERIAL_NUMBER.length();
			StringBuilder sb = new StringBuilder();
			for (int i = 1; i <= count; i++) {
				sb.append("0");
			}
			DecimalFormat df = new DecimalFormat("0000");
			id = formatter.format(date) + df.format(1 + Integer.parseInt(sno));
		}
		return id;
	}
	
	

	/**
	 * 4位随机数
	 * @return
	 */
	public int Getrandom()
	{
		int x;//定义两变量
        Random ne=new Random();//实例化一个random的对象ne
        x=ne.nextInt(9999-1000+1)+1000;//为变量赋随机值1000-9999
        return x;
	}
	
	public String getMaxID()
	{
		Date date = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmssms");
		return formatter.format(date)+Getrandom();
	}
}
